package eu.vranckaert.workRegistrationWidget.dao.helper;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import eu.vranckaert.workRegistrationWidget.dao.util.DatabaseVars;

/* TODO refactor to use the DatabaseVars! */
public class MySQLiteOpenHelper extends SQLiteOpenHelper {
    public MySQLiteOpenHelper(Context context) {
        super(context, DatabaseVars.DATABASE_NAME, null, DatabaseVars.DATABASE_VERSION);
    }

    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("create table categories (id integer primary key autoincrement, name text not null);");
        sqLiteDatabase.execSQL("create table timereg (id integer primary key autoincrement, startdate integer not null, enddate integer null, startLatitude varchar null, startLongtitude varchar null, endLatitude varchar null, endLongtitude varchar null, catid integer null);");

        ContentValues values = new ContentValues();
        values.put("name", "Office");
        sqLiteDatabase.insert("categories", null, values);
    }

    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int old, int new1) {
        sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + DatabaseVars.TABLE_TIMEREG);
        sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + DatabaseVars.TABLE_CAT);
        onCreate(sqLiteDatabase);
    }
}
